package tv.starfu.game.loaders;

import com.artemis.utils.ImmutableBag;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.EntitySystem;
import com.artemis.World;
import com.jme3.renderer.Camera;
import tv.starfu.animae.Tile;

/**
 * Uses the camera system to stream in level contents as the player moves through the level.
 * 
 * @author Oliver
 */
public class LevelBuilder extends EntitySystem
{
	private World world;
	private Camera cam;
	private List<Entity> contents;

	private int index;
	private float margin;

	public LevelBuilder(World world)
	{
		this(world, 32f);
	}

	public LevelBuilder(World world, float margin)
	{
		this.world = world;
		this.margin = margin;
	}

	public void initialize()
	{
//		cam = world.getSystemManager().getSystem(CameraSystem.class);
//		transformMapper = new ComponentMapper<Transform>(Transform.class, world);
//
//		MapLoader loader = new MapLoader(world);
//		try
//		{
//			contents = loader.buildMap("/levels/level_1.map");
//			Collections.sort(contents, new TransformXComparator());
//		}
//		catch (FileNotFoundException e)
//		{
//			e.printStackTrace();
//		}
	}

	public void update()
	{
//		while(index < contents.size())
//		{
//			Entity e = contents.get(index);
//			Transform t = transformMapper.get(e);
//			
//			if (t == null || t.getX() - cam.getEndX() < margin)
//			{
//				e.refresh();
//				++index;
//			}
//			else
//			{
//				break;
//			}
//		}
	}

    @Override
    protected void processEntities(ImmutableBag<Entity> entities) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected boolean checkProcessing() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

	
}
